home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / WebObjects / SourceCode / Create-A-Card / Main.wo / Main.wos < prev   
Text File  |  1996-01-25  |  2KB  |  79 lines

  1. /*
  2.  *   Main.wos
  3.  *   You may freely copy, distribute, and reuse the code in this example.
  4.  *   NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  5.  *   fitness for any particular use.
  6.  *    
  7.  *     Written by Katie McCormick
  8.  *
  9.  */
  10.  
  11. id nameString;
  12. id ageString;
  13. id messageString;
  14.  
  15. - awake {        
  16.     if(!messageString)
  17.     messageString = @"Type your birthday message here.";
  18. }
  19.  
  20. - happyBirthday
  21. {
  22.     id nextPage, nameDict, suffix, age, result;
  23. //
  24. // Create a dictionary to hold the name of the current recipient
  25. // 
  26.     nameDict = [NSMutableDictionary dictionary];
  27. //
  28. // Put the current recipient in the dictionary
  29. //
  30.     [nameDict setObject:nameString forKey:@"aName"]; 
  31. //
  32. // Add the dictionary containing the recipient's name to the global
  33. // variable namesArray. This array maintains a list of all recipients
  34. // across all sessions. When a user clicks the 'Show all recipients'
  35. // button, namesArray is iterated to display all recipient names.
  36. //
  37.     [[WOApp namesArray] addObject:nameDict];    
  38.     
  39. //
  40. // Figure out the right suffix to append to the recipient's age
  41. //
  42.     age = [ageString intValue];
  43.     result = age % 10;
  44.     if(result == 1 && age !=11)
  45.     suffix = @"st";    
  46.     else if (result == 2 && age != 12)
  47.     suffix = @"nd";
  48.     else if (result == 3 && age != 13)
  49.     suffix = @"rd";
  50.     else
  51.     suffix = @"th";
  52.  
  53. //
  54. // Set the values of variables declared in the page "HappyBirthday"
  55. //     
  56.     nextPage = [WOApp pageWithName:@"HappyBirthday"]; 
  57.     [nextPage setNameString:nameString];    
  58.     [nextPage setAgeSuffix:suffix];
  59.     [nextPage setAgeString:ageString];
  60. //
  61. // If the user didn't type a message, set messageString to be an empty
  62. // string.
  63. //
  64.     if ([messageString isEqualToString:@"Type your birthday message here."])
  65.         messageString = @"";
  66.     [nextPage setMessageString:messageString];
  67.     return nextPage;
  68. }
  69.  
  70. //
  71. // Show all of the recipients, across all sessions
  72. //
  73. - showRecipients
  74. {
  75.     id nextPage;
  76.     nextPage = [WOApp pageWithName:@"Recipients"]; 
  77.     return nextPage;
  78. }
  79.